<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 在数组原型上添加 myFilter 方法
      Array.prototype.myFilter = function (callback) {
        let newArr = []
        for (let i = 0; i < this.length; i++) {
          if (callback(this[i], i, this)) {
            newArr.push(this[i])
            
          }
        }
        return newArr
      }
      let arr = [1, 4, 5, 8]
      const resu = arr.myFilter((item) => {
        return item > 5
      })
      console.log(resu)
    </script>
  </body>
</html>
